﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TowerTroopGenerator : MonoBehaviour {
    public Tower tower;
    public GameObject TroopPrefab;
    public Transform InitTroopPivot;

    public Timer timer;
    public float SummonTroopTime;
    public Renderer SummonCoolDownBar;


    private void Awake()
    {
        timer = new Timer(SummonTroopTime);
    }


    private void Update()
    {
        SummonCoolDownBar.material.SetFloat("_Prograss", timer.currentTime / SummonTroopTime);
        if (tower.TowerOwner == PlayerType.Player)
        {
            if(timer.Tick(Time.deltaTime))
            {
                Instantiate(TroopPrefab, InitTroopPivot.position, InitTroopPivot.rotation);
            }
        }
        else
        {
            timer.Reset();
        }
    }


}
